/*
 * 文 件 名 : HelpActivity.java
 * 版    权 : China Machi.Co.,Ltd.Copyright 2009-2011.All rights reserved
 * 描    述 : <描述>
 * 修 改 人 : lixg
 * 修改时间 : 2012-11-29
 * 跟踪单号 : <跟踪单号>
 * 修改单号 : <修改单号>
 * 修改内容 : <修改内容>
 */
package com.fire8.dolphin.ui.more;

import java.util.ArrayList;

import android.app.Activity;
import android.os.Bundle;
import android.os.Parcelable;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout.LayoutParams;

import com.fire8.dolphin.ui.R;

/**
 * 帮助页面
 *
 * @author  lixg
 * @version [版本号,2012-11-29]
 * @see     [相关类/方法]
 * @since   [产品/模块]
 */
public class HelpActivity extends Activity
{
    private ViewPager viewPager;  
    private ArrayList<View> pageViews;  
    private ImageView imageView;  
    private ImageView[] imageViews; 
    // 包裹滑动图片LinearLayout
    private ViewGroup main;
    // 包裹小圆点的LinearLayout
    private ViewGroup group;
    
    private Button btnStart1;
       
   /** Called when the activity is first created. */
   @Override
   public void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       // 设置无标题窗口
       requestWindowFeature(Window.FEATURE_NO_TITLE);
       
       LayoutInflater inflater = getLayoutInflater();  
       pageViews = new ArrayList<View>();  
       //View vZero = inflater.inflate(R.layout.welcome_zero, null);
       //btnStart1 = (Button)vZero.findViewById(R.id.btn_start);
       //btnStart1.setOnClickListener(new ButtonClickListener());
       //View vFour = inflater.inflate(R.layout.welcome_four, null);
       //Button btnStart2 = (Button)vFour.findViewById(R.id.btn_start);
       //btnStart2.setOnClickListener(new ButtonClickListener());
       
       View vStart = inflater.inflate(R.layout.welcome_start, null);
       Button btnStart3 = (Button)vStart.findViewById(R.id.btn_start);
       btnStart3.setOnClickListener(new ButtonClickListener());
       
       pageViews.add(getImageView(R.drawable.welcome_radio));
       pageViews.add(getImageView(R.drawable.welcome_plan));
       pageViews.add(getImageView(R.drawable.welcome_diary));
       
       pageViews.add(vStart);
//       pageViews.add(inflater.inflate(R.layout.item06, null));
//       pageViews.add(inflater.inflate(R.layout.item01, null));  
//       pageViews.add(inflater.inflate(R.layout.item02, null));  
//       pageViews.add(inflater.inflate(R.layout.item03, null));  
//       pageViews.add(inflater.inflate(R.layout.item04, null));  
       
       imageViews = new ImageView[pageViews.size()];  
       main = (ViewGroup)inflater.inflate(R.layout.help_layout, null);  
       
       group = (ViewGroup)main.findViewById(R.id.viewGroup);  
       viewPager = (ViewPager)main.findViewById(R.id.guidePages);  
       
       for (int i = 0; i < pageViews.size(); i++) {  
           imageView = new ImageView(HelpActivity.this);  
           imageView.setLayoutParams(new LayoutParams(20,20));  
           imageView.setPadding(20, 0, 20, 0);  
           imageViews[i] = imageView;  
           
           if (i == 0) {  
               //默认选中第一张图片
               imageViews[i].setBackgroundResource(R.drawable.page_indicator_focused);  
           } else {  
               imageViews[i].setBackgroundResource(R.drawable.page_indicator);  
           }  
           
           group.addView(imageViews[i]);  
       }  
       
       setContentView(main);
       
       viewPager.setAdapter(new GuidePageAdapter());  
       viewPager.setOnPageChangeListener(new GuidePageChangeListener());  
   }
   
   /** 按钮点击事件***/
   class ButtonClickListener implements OnClickListener
   {
        @Override
        public void onClick(View v)
        {
            HelpActivity.this.finish();
        }
   }
   private View getImageView(int id)
   {
       ImageView iv = new ImageView(this);
       iv.setImageResource(id);
       return iv;
   }
   
   // 指引页面数据适配器
   class GuidePageAdapter extends PagerAdapter {  
     
       @Override  
       public int getCount() {  
           return pageViews.size();  
       }  
 
       @Override  
       public boolean isViewFromObject(View arg0, Object arg1) {  
           return arg0 == arg1;  
       }  
 
       @Override  
       public int getItemPosition(Object object) {  
           return super.getItemPosition(object);  
       }  
 
       @Override  
       public void destroyItem(View arg0, int arg1, Object arg2) {  
           ((ViewPager) arg0).removeView(pageViews.get(arg1));  
       }  
 
       @Override  
       public Object instantiateItem(View arg0, int arg1) {  
           ((ViewPager) arg0).addView(pageViews.get(arg1));  
           return pageViews.get(arg1);  
       }  
 
       @Override  
       public void restoreState(Parcelable arg0, ClassLoader arg1) {  
 
       }  
 
       @Override  
       public Parcelable saveState() {  
           return null;  
       }  
 
       @Override  
       public void startUpdate(View arg0) {  
 
       }  
 
       @Override  
       public void finishUpdate(View arg0) {  
 
       }  
   } 
   
   // 指引页面更改事件监听器
   class GuidePageChangeListener implements OnPageChangeListener {  
         
       @Override  
       public void onPageScrollStateChanged(int arg0) {  
 
       }  
 
       @Override  
       public void onPageScrolled(int arg0, float arg1, int arg2) {  
 
       }  
 
       @Override  
       public void onPageSelected(int arg0) {  
           for (int i = 0; i < imageViews.length; i++) {  
               imageViews[arg0].setBackgroundResource(R.drawable.page_indicator_focused);
               
               if (arg0 != i) {  
                   imageViews[i].setBackgroundResource(R.drawable.page_indicator);  
               }  
           }
       }  
   }  
}
